package model

import (
	"time"
)

type User struct {
	ID            uint      `json:"id" gorm:"primaryKey"`
	OpenID        string    `json:"openid" gorm:"column:openid;uniqueIndex;not null"`
	Phone         string    `json:"phone" gorm:"index"`
	Nickname      string    `json:"nickname"`
	AvatarURL     string    `json:"avatar_url"`
	TotalDays     int       `json:"total_days" gorm:"default:0"`
	TotalItems    int       `json:"total_items" gorm:"default:0"`
	CurrentStreak int       `json:"current_streak" gorm:"default:0"`
	LongestStreak int       `json:"longest_streak" gorm:"default:0"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`

	CheckInRecords []CheckInRecord `json:"check_in_records" gorm:"foreignKey:UserID"`
}

type CheckInRecord struct {
	ID              uint      `json:"id" gorm:"primaryKey"`
	UserID          uint      `json:"user_id" gorm:"not null;index"`
	ItemName        string    `json:"item_name" gorm:"not null"`
	ItemCategory    string    `json:"item_category" gorm:"index"`
	ItemDescription string    `json:"item_description"`
	ItemReason      string    `json:"item_reason"`
	ItemImage       string    `json:"item_image"`
	CheckInDate     time.Time `json:"check_in_date" gorm:"not null;index"`
	CreatedAt       time.Time `json:"created_at"`

	User User `json:"user" gorm:"foreignKey:UserID"`
}

type UserStatistic struct {
	ID            uint      `json:"id" gorm:"primaryKey"`
	UserID        uint      `json:"user_id" gorm:"not null;index"`
	StatDate      time.Time `json:"stat_date" gorm:"not null;index"`
	TotalItems    int       `json:"total_items" gorm:"default:0"`
	CategoryStats string    `json:"category_stats" gorm:"type:text"`
	MonthTotal    int       `json:"month_total" gorm:"default:0"`
	YearTotal     int       `json:"year_total" gorm:"default:0"`
	CreatedAt     time.Time `json:"created_at"`
}

type WechatLoginRequest struct {
	Code string `json:"code" binding:"required"`
}

type PhoneLoginRequest struct {
	Code      string `json:"code" binding:"required"`
	PhoneCode string `json:"phone_code" binding:"required"`
}

type CheckInRequest struct {
	ItemName        string `json:"item_name" binding:"required"`
	ItemCategory    string `json:"item_category"`
	ItemDescription string `json:"item_description"`
	ItemReason      string `json:"item_reason"`
	ItemImage       string `json:"item_image"`
}

type UpdateCheckInRequest struct {
	ItemName        string `json:"item_name"`
	ItemCategory    string `json:"item_category"`
	ItemDescription string `json:"item_description"`
	ItemReason      string `json:"item_reason"`
	ItemImage       string `json:"item_image"`
}

type StatisticsOverview struct {
	TotalDays     int            `json:"total_days"`
	TotalItems    int            `json:"total_items"`
	CurrentStreak int            `json:"current_streak"`
	LongestStreak int            `json:"longest_streak"`
	CategoryStats map[string]int `json:"category_stats"`
	MonthlyData   []MonthlyStat  `json:"monthly_data"`
}

type MonthlyStat struct {
	Month string `json:"month"`
	Count int    `json:"count"`
}

type CalendarData struct {
	Year  int           `json:"year"`
	Month int           `json:"month"`
	Days  []CalendarDay `json:"days"`
}

type CalendarDay struct {
	Date       string `json:"date"`
	Day        int    `json:"day"`
	HasCheckIn bool   `json:"has_check_in"`
	ItemCount  int    `json:"item_count"`
}

type TrendData struct {
	Dates  []string `json:"dates"`
	Counts []int    `json:"counts"`
}

type APIResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}
